package org.lg.studyspringboot20.controller;


import org.lg.studyspringboot20.aop.SendmasgLog;
import org.lg.studyspringboot20.aop.SystemLog;
import org.lg.studyspringboot20.dto.DTO;
import org.lg.studyspringboot20.entity.Admin;
import org.lg.studyspringboot20.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;
import java.util.List;

@Controller //@Controller @Service @Repository @Component
@RequestMapping("/adminController")
public class AdminController //extends HttpServlet
{
    @Autowired
    AdminService adminService;// dao 不 new但是能够使用是因为 spring的ioc（invers of controll 反转控制，对象的生成由容器（小容器spring 大容器tomcat）完成） 生成了对象

    public AdminService getAdminService() {
        return adminService;
    }

    public void setAdminService(AdminService adminService) {
        this.adminService = adminService;
    }


    public AdminController() throws IllegalAccessException, SQLException, ClassNotFoundException {
    }
    @RequestMapping("/getAll")
    @ResponseBody
    @SystemLog(module = "管理员模块",methods = "查询所有")
    public DTO getAll() throws Exception{
        return adminService.getAllAdmin();
    }

    @RequestMapping("/add")
    @ResponseBody
    @SendmasgLog
    @SystemLog(module = "管理员模块",methods = "增加")
    public DTO add(Admin admin) throws Exception {
        return adminService.add(admin);
    }
    @RequestMapping("/update")
    @ResponseBody
    @SendmasgLog
    @SystemLog(module = "管理员模块",methods = "修改")
    public DTO update(Admin admin) throws Exception {
        System.out.println(admin);
        return adminService.update(admin);
    }
}
